package tests;

import simulation.AgentManager;
import simulation.TrafficInfrastructureManager;
import agents.exceptions.ActionFailedException;
import agents.resource.CrossRoadAgent;
import agents.resource.ResourceAgent;
import agents.resource.RoadAgent;
import domain.Car;
import facade.TrafficInfrastructureFacade;
import gui.MainWindow;

public class TestInfrastructure {
	
	public static void main(String[] args) {
		TestInfrastructure e = new TestInfrastructure();
		TrafficInfrastructureManager infrastructure = e.getInfrastructure();
		
		TrafficInfrastructureFacade t = new TrafficInfrastructureFacade(infrastructure);
		
		MainWindow mainWindow = new MainWindow(t);
		mainWindow.setVisible(true);

		e.runCommands();
	}
	
	public TestInfrastructure(){
		ExperimentSetup e= new ExperimentSetup1();
		agents = e.getAgents();
		infrastructure = e.getInfrastructure();
	}
	
	public TrafficInfrastructureManager getInfrastructure(){
		return infrastructure;
	}
	
	public AgentManager getAgents(){
		return agents;
	}
	
	private TrafficInfrastructureManager infrastructure;
	private AgentManager agents;
	
	private void runCommands() {
	
		//agentC1, agent12, agent13, pk, renault
		CrossRoadAgent agentC1 = (CrossRoadAgent) agents.getResourceAgentOf("c1");
		RoadAgent agent21 = (RoadAgent) agents.getResourceAgentOf("road21");
		ResourceAgent agent13 = agents.getResourceAgentOf("road13");
		
		Car renault = infrastructure.getCar("renault");
		Car pk = infrastructure.getCar("pk");
		
		try {
		
			Thread.sleep(1000);
			agent21.advance(renault);
			Thread.sleep(1000);
			agent21.advance(pk);
			Thread.sleep(1000);
			agentC1.moveTo(agentC1.getTrafficInfrastructure().getSegment().getCar(),agent13);
			Thread.sleep(1000);
			agent21.advance(renault);
			Thread.sleep(1000);
			agent21.advance(pk);
			Thread.sleep(1000);
			agent21.advance(renault);
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (ActionFailedException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		
	}
}
